let exchangeMap= [{
      'name':'MDPOX ',
      'symbol':'MDPOX ',
      'address':'0x020294B51D279Ef70C710d5B993AE5017a9bbBaF',
      'decimals':8,
      'img':'static/img/coin/MDPOX.png',
       'abi':[
         {
           "constant": true,
           "inputs": [],
           "name": "lv4",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "name",
           "outputs": [
             {
               "name": "",
               "type": "string"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": false,
           "inputs": [
             {
               "name": "_spender",
               "type": "address"
             },
             {
               "name": "_value",
               "type": "uint256"
             }
           ],
           "name": "approve",
           "outputs": [
             {
               "name": "success",
               "type": "bool"
             }
           ],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "totalSupply",
           "outputs": [
             {
               "name": "supply",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": false,
           "inputs": [
             {
               "name": "_from",
               "type": "address"
             },
             {
               "name": "_to",
               "type": "address"
             },
             {
               "name": "_value",
               "type": "uint256"
             }
           ],
           "name": "transferFrom",
           "outputs": [],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "name": "dateToYields",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": false,
           "inputs": [
             {
               "name": "_target",
               "type": "address"
             },
             {
               "name": "_islock",
               "type": "bool"
             }
           ],
           "name": "lockAddr",
           "outputs": [
             {
               "name": "",
               "type": "bool"
             }
           ],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [
             {
               "name": "",
               "type": "address"
             }
           ],
           "name": "balances",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": false,
           "inputs": [
             {
               "name": "_yield",
               "type": "uint256"
             }
           ],
           "name": "setMinerYield",
           "outputs": [
             {
               "name": "success",
               "type": "bool"
             }
           ],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "decimals",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "lv5S",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": false,
           "inputs": [
             {
               "name": "_index",
               "type": "uint256"
             },
             {
               "name": "_lvs",
               "type": "uint256"
             }
           ],
           "name": "setLVS",
           "outputs": [
             {
               "name": "success",
               "type": "bool"
             }
           ],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "lv4S",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "_totalSupply",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": false,
           "inputs": [
             {
               "name": "_index",
               "type": "uint256"
             },
             {
               "name": "_yield",
               "type": "uint256"
             }
           ],
           "name": "setDateToYield",
           "outputs": [
             {
               "name": "success",
               "type": "bool"
             }
           ],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [
             {
               "name": "_addr",
               "type": "address"
             }
           ],
           "name": "freeAmount",
           "outputs": [
             {
               "name": "amount",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "founder",
           "outputs": [
             {
               "name": "",
               "type": "address"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "lv1S",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [
             {
               "name": "",
               "type": "address"
             },
             {
               "name": "",
               "type": "address"
             }
           ],
           "name": "allowed",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "lv1",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [
             {
               "name": "",
               "type": "address"
             }
           ],
           "name": "lockAddrs",
           "outputs": [
             {
               "name": "",
               "type": "bool"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [
             {
               "name": "_owner",
               "type": "address"
             }
           ],
           "name": "balanceOf",
           "outputs": [
             {
               "name": "balance",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [
             {
               "name": "",
               "type": "address"
             },
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "name": "addressToPledge",
           "outputs": [
             {
               "name": "userAddress",
               "type": "address"
             },
             {
               "name": "investAmount",
               "type": "uint256"
             },
             {
               "name": "yield",
               "type": "uint256"
             },
             {
               "name": "lvs",
               "type": "uint256"
             },
             {
               "name": "createTime",
               "type": "uint256"
             },
             {
               "name": "dueTime",
               "type": "uint256"
             },
             {
               "name": "mdacxAmount",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "lv6",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "lv2",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "lv2S",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": false,
           "inputs": [
             {
               "name": "_targets",
               "type": "address[]"
             },
             {
               "name": "_islock",
               "type": "bool"
             }
           ],
           "name": "multiLockAddr",
           "outputs": [
             {
               "name": "",
               "type": "bool"
             }
           ],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "function"
         },
         {
           "constant": false,
           "inputs": [
             {
               "name": "newFounder",
               "type": "address"
             }
           ],
           "name": "changeFounder",
           "outputs": [],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "symbol",
           "outputs": [
             {
               "name": "",
               "type": "string"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "lv3",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": false,
           "inputs": [
             {
               "name": "_to",
               "type": "address"
             },
             {
               "name": "_value",
               "type": "uint256"
             }
           ],
           "name": "transfer",
           "outputs": [],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "function"
         },
         {
           "constant": false,
           "inputs": [
             {
               "name": "_index",
               "type": "uint256"
             },
             {
               "name": "_lv",
               "type": "uint256"
             }
           ],
           "name": "setLV",
           "outputs": [
             {
               "name": "success",
               "type": "bool"
             }
           ],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [
             {
               "name": "_addr",
               "type": "address"
             }
           ],
           "name": "getAddrPledgeCount",
           "outputs": [
             {
               "name": "amount",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "lv5",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": false,
           "inputs": [
             {
               "name": "_amount",
               "type": "uint256"
             },
             {
               "name": "_mode",
               "type": "uint256"
             }
           ],
           "name": "exchange",
           "outputs": [
             {
               "name": "success",
               "type": "bool"
             }
           ],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [
             {
               "name": "_owner",
               "type": "address"
             },
             {
               "name": "_spender",
               "type": "address"
             }
           ],
           "name": "allowance",
           "outputs": [
             {
               "name": "remaining",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "minerYield",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "lv3S",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "constant": true,
           "inputs": [],
           "name": "lv6S",
           "outputs": [
             {
               "name": "",
               "type": "uint256"
             }
           ],
           "payable": false,
           "stateMutability": "view",
           "type": "function"
         },
         {
           "inputs": [],
           "payable": false,
           "stateMutability": "nonpayable",
           "type": "constructor"
         },
         {
           "anonymous": false,
           "inputs": [
             {
               "indexed": true,
               "name": "owner",
               "type": "address"
             },
             {
               "indexed": true,
               "name": "spender",
               "type": "address"
             },
             {
               "indexed": false,
               "name": "value",
               "type": "uint256"
             }
           ],
           "name": "Approval",
           "type": "event"
         },
         {
           "anonymous": false,
           "inputs": [
             {
               "indexed": true,
               "name": "from",
               "type": "address"
             },
             {
               "indexed": true,
               "name": "to",
               "type": "address"
             },
             {
               "indexed": false,
               "name": "value",
               "type": "uint256"
             }
           ],
           "name": "Transfer",
           "type": "event"
         }
       ],
       supportCoinArray:[
        {
          'name':'大奖章',
          'symbol':'MDAC',
          'address':'0xa2031e2ce434e7d0dd5841021b734f1e8c8d58ab',
          'rate':1,
          'decimals':18,
          'sign':1,
          'img':'static/img/coin/MDAC.png',
          'abi':[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"finance","type":"address"}],"name":"delFinance","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"totalsupply","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"allowanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"finances","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"tokenOwner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"content","type":"string"}],"name":"financeReportForm","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newFinance","type":"address"}],"name":"addFinance","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_tokenName","type":"string"},{"name":"_tokenSymbol","type":"string"},{"name":"_tokenDecimals","type":"uint8"},{"name":"_tokenTotalSupply","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"newFinance","type":"address"},{"indexed":false,"name":"success","type":"bool"}],"name":"addFinanceEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"newFinance","type":"address"},{"indexed":false,"name":"success","type":"bool"}],"name":"delFinanceEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"tokens","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenOwner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"tokens","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"content","type":"string"}],"name":"ReportFormEvent","type":"event"}]
        }
      ]
    }
]

let convertBigNumber=(param)=>{
  let strParam = String(param)
  let flag = /e/.test(strParam)
  if (!flag) return param

  // 指数符号 true: 正，false: 负
  let sysbol = true
  if (/e-/.test(strParam)) {
    sysbol = false
  }
  // 指数
  let index = Number(strParam.match(/\d+$/)[0])
  // 基数
  let basis = strParam.match(/^[\d\.]+/)[0].replace(/\./, '')

  if (sysbol) {
    return basis.padEnd(index + 1, 0)
  } else {
    return basis.padStart(index + basis.length, 0).replace(/^0/, '0.')
  }
}


//type 1:兑换,2赎回
let calculateRate=(coin,amount,type)=>{
  console.log(coin)
    let rate=coin.rate;
    let sign=coin.sign;
    if(type==1){
      if(sign==1){
        return convertBigNumber(amount/rate);
      }else if(sign==2){
        return convertBigNumber(amount*rate);
      }
    }else if(type==2){
      if(sign==1){
        return convertBigNumber(amount*rate);
      }else if(sign==2){
        return convertBigNumber(amount/rate);
      }

    }else{
      return -1;
    }
}


module.exports={
  exchangeMap,calculateRate
}
